< previous page page_458 next page >

Page 458
LISTING 20.4.CONTINUED
9f8044bafea36a1f728739c0bb58ef4c.gif
 41:
 42:     'Connect to database and login here. Data Access
 43:     'subsystem usage simplified here to avoid a
 44:     'clutter of code
 45:     Dim sConn As String
 46:     Set theDBConnection = New DBAdoConnection
 47:     sCOnn =  DSN=CorporateDB;UID=JSmith;PWD=greetings
 48:     theDBConnection.OpenConnectionWithDSN sConn
 49:     If theDBConnection.isConnected Then
 50:         isLoggedIn = authenticated
 51:     End If
 52:     If isLoggedIn Then
 53:         'Normally, you
 54:         theAppTransactions.addTrans2MemLog _
 55:             User  & theApplication.theUser.UserID &
                    has logged in at   & Now$
 56:
 57:         theApplication.theMDIController.enableProcessMenu
 58:     End If
 59:     'Normally, you would check the database
 60:     'to see to which workgroup a user belongs
 61:     Set theApplication.theSomeWorkgroupProxy = New SomeWorkgroupProxy
 62:     theApplication.theSomeWorkgroupProxy.startProcess
 63:
 64:     'MsgBox theApplication.theUser.UserID & vbNewLine _
 65:     ' & theApplication.theUser.UserPassword & vbNewLine & isLoggedIn
 66:     'Note that the encrypted password should be persisted
 67: End Sub
 68:
 69: 'In DBAdoConnection
 70: Public Sub openConnectionWithDSN(argConnStr As String) 'As Variant
 71:     On Error GoTo openConnectionErr
 72:     Set mvarpDBConnection = New ADODB.Connection
 73:     With mvarpDBConnection
 74:         ' Open a connection using an ODBC DSN.
 75:         .ConnectionString = argConnStr 'DSN=Pubs;UID=sa;PWD=;
 76:         .ConnectionTimeout = 30
 77:         .Open
 78:         ' Find out if the attempt to connect worked.
 79: '        If .State = adStateOpen Then
 80: '            MsgBox Connection successfully established
 81: '        Else
 82: '           MsgBox Connection not successfully established
 83: '        End If
 84:     End With
 85:     Exit Sub
 86: openConnectionErr:
 87: '    For Each m_rdoError In rdoErrors
continues

 
< previous page page_458 next page >

If you like this book, buy it!